package com.jtlrm.ckd.mvp.view.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.base.sdk.base.api.PositiveOrCancelInterface;
import com.base.sdk.util.DialogUtil;
import com.base.sdk.util.ImageUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jtlrm.ckd.R;
import com.jtlrm.ckd.config.CodeConstants;
import com.jtlrm.ckd.entity.NewsEntity;
import com.jtlrm.ckd.entity.SuiFangPaiBanEntity;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuLayout;

public class SuiFangPaiBanAdapter extends BaseQuickAdapter<SuiFangPaiBanEntity, BaseViewHolder> {

    MenuListener menuListener;

    public SuiFangPaiBanAdapter() {
        super(R.layout.suifang_paiban_item);
    }


    public void setMenuListener(MenuListener listener) {
        this.menuListener = listener;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final SuiFangPaiBanEntity item) {
        ImageUtil.loadCircleAvatarImage((ImageView) helper.getView(R.id.avatar), item.getHeadPicture());
        helper.setText(R.id.name, item.getName());
        helper.setText(R.id.sex, item.getSex());
        helper.setText(R.id.age, item.getAge() + "岁");
        helper.setText(R.id.last_time, "上次随访:" + item.getLastVisitTime());
        helper.setText(R.id.next_time, "下次随访:" + item.getVisitTime());
        if ("APP".equals(item.getRegisterType() + "")) {
            ((ImageView) helper.getView(R.id.register_type)).setImageResource(R.drawable.manager_phone_icon);
        } else {
            ((ImageView) helper.getView(R.id.register_type)).setImageResource(R.drawable.manager_messgae_icon);
        }
        SwipeMenuLayout swipeMenuLayout = helper.getView(R.id.SwipeMenuLayout);
        swipeMenuLayout.smoothCloseMenu();
        if ("1".equals(item.getIsBefore() + "")) {
            swipeMenuLayout.setSwipeEnable(true);
        } else {
            swipeMenuLayout.setSwipeEnable(false);
        }
        helper.getView(R.id.change_date).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (menuListener != null)
                    menuListener.changeDate(item);
            }
        });
        helper.getView(R.id.delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtil.showDialog(mContext, CodeConstants.DELETE_SUIFANGPAIBAN, new PositiveOrCancelInterface() {
                    @Override
                    public void result(boolean result) {
                        if (result) {
                            if (menuListener != null)
                                menuListener.deletePaiBan(item);
                        }
                    }
                });

            }
        });
    }

    public interface MenuListener {
        void changeDate(SuiFangPaiBanEntity item);

        void deletePaiBan(SuiFangPaiBanEntity item);
    }
}
